﻿<%@ Page Title="Promotion Setup" Language="C#" MasterPageFile="~/Popup.Master" AutoEventWireup="true"
    CodeBehind="PromotionDetailForView.aspx.cs" Inherits="PromotionEngine.PromotionDetailForView" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        var promotionID;
        var promotionDetail = {};
        var jsonReferenceValueDiscountType;
        var jsonReferenceValuePropertyValueType;
        var ddlPromotion;
        var dllDiscount;
        var MondayStart, TuesdayStart, WednesdayStart, ThursdayStart, FridayStart, SaturdayStart, SunDayStart;
        var MondayEnd, TuesdayEnd, WednesdayEnd, ThursdayEnd, FridayEnd, SaturdayEnd, SunDayEnd;
        var FromDate, ToDate, FromTime, ToTime;
        var MaxCountApply, FromAmount, ToAmount, BudgetAmount, FromQuantity, ToQuantity, TargetRevenue, DiscountValue;
        var IsInsert = false;
        function GetDocPromotionHeader() {
            $.ajax({
                type: "POST",
                url: "PromotionDetailForView.aspx/GetPromotionHeaderDetail",
                data: JSON.stringify({
                    promotionID: promotionID
                }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var result = JSON.parse(response.d);
                    if (result.Data && promotionID != '0') {
                        promotionDetail = result.Data;
                        setValueTextBox(promotionDetail);
                        setValueCheckBox(promotionDetail);
                        $("#DiscountType").data("kendoDropDownList").value(promotionDetail.DiscountType);
                        $("#PromotionType").data("kendoDropDownList").value(promotionDetail.PromotionType);
                        $("#PromotionCode").val(promotionDetail.PromotionCode);
                        $("#PromotionName").val(promotionDetail.PromotionName);
                        $("#FatherPromotionCode").val(promotionDetail.FatherPromotionCode);
                        //Date
                        FromDate.value(kendo.parseDate(promotionDetail.FromDate));
                        ToDate.value(kendo.parseDate(promotionDetail.ToDate));
                        //Start
                        MondayStart.value(kendo.parseDate(promotionDetail.MondayStart));
                        TuesdayStart.value(kendo.parseDate(promotionDetail.TuesdayStart));
                        WednesdayStart.value(kendo.parseDate(promotionDetail.WednesdayStart));
                        ThursdayStart.value(kendo.parseDate(promotionDetail.ThursdayStart));
                        FridayStart.value(kendo.parseDate(promotionDetail.FridayStart));
                        SaturdayStart.value(kendo.parseDate(promotionDetail.SaturdayStart));
                        SunDayStart.value(kendo.parseDate(promotionDetail.SundayStart));
                        //End
                        MondayEnd.value(kendo.parseDate(promotionDetail.MondayEnd));
                        TuesdayEnd.value(kendo.parseDate(promotionDetail.TuesdayEnd));
                        WednesdayEnd.value(kendo.parseDate(promotionDetail.WednesdayEnd));
                        ThursdayEnd.value(kendo.parseDate(promotionDetail.ThursdayEnd));
                        FridayEnd.value(kendo.parseDate(promotionDetail.FridayEnd));
                        SaturdayEnd.value(kendo.parseDate(promotionDetail.SaturdayEnd));
                        SunDayEnd.value(kendo.parseDate(promotionDetail.SundayEnd));
                        //Time
                        if (promotionDetail.FromTime != null) {
                            FromTime.value(kendo.parseDate(promotionDetail.FromTime));
                        }
                        if (promotionDetail.ToTime != null) {
                            ToTime.value(kendo.parseDate(promotionDetail.ToTime));
                        }
                        //Amount
                        MaxCountApply.value(promotionDetail.MaxCountApply);
                        FromAmount.value(promotionDetail.FromAmount);
                        ToAmount.value(promotionDetail.ToAmount);
                        BudgetAmount.value(promotionDetail.BudgetAmount);
                        FromQuantity.value(promotionDetail.FromQuantity);
                        ToQuantity.value(promotionDetail.ToQuantity);
                        TargetRevenue.value(promotionDetail.TargetRevenue);
                        DiscountValue.value(promotionDetail.DiscountValue);
                    }
                    else {
                    }
                },
                failure: function (response) {

                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    alert(errorThrown);
                    if (jqXHR.status == 500) {
                        alert('Internal error: ' + jqXHR.responseText);
                    } else {
                        alert('Unexpected error.' + jqXHR.responseText);
                    }
                }
            });
        }
        $(document).ready(function () {
            var today = new Date();
            //START
            MondayStart = $("#MondayStart").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate())
            }).data("kendoTimePicker");

            TuesdayStart = $("#TuesdayStart").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate())
            }).data("kendoTimePicker");

            WednesdayStart = $("#WednesdayStart").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate())
            }).data("kendoTimePicker");

            ThursdayStart = $("#ThursdayStart").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate())
            }).data("kendoTimePicker");

            FridayStart = $("#FridayStart").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate())
            }).data("kendoTimePicker");

            SaturdayStart = $("#SaturdayStart").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate())
            }).data("kendoTimePicker");

            SunDayStart = $("#SundayStart").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate())
            }).data("kendoTimePicker");

            //END
            MondayEnd = $("#MondayEnd").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59)
            }).data("kendoTimePicker");
            TuesdayEnd = $("#TuesdayEnd").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59)
            }).data("kendoTimePicker");

            WednesdayEnd = $("#WednesdayEnd").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59)
            }).data("kendoTimePicker");

            ThursdayEnd = $("#ThursdayEnd").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59)
            }).data("kendoTimePicker");

            FridayEnd = $("#FridayEnd").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59)
            }).data("kendoTimePicker");

            SaturdayEnd = $("#SaturdayEnd").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59)
            }).data("kendoTimePicker");

            SunDayEnd = $("#SundayEnd").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59)
            }).data("kendoTimePicker");


            //Header 
            FromDate = $("#FromDate").kendoDatePicker({
                value: new Date()
            }).data("kendoDatePicker");
            ToDate = $("#ToDate").kendoDatePicker({
                value: new Date()
            }).data("kendoDatePicker");
            FromTime = $("#FromTime").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate())
            }).data("kendoTimePicker");
            ToTime = $("#ToTime").kendoTimePicker({
                format: "HH:mm:ss",
                parseFormats: ["HH:mm:ss"],
                value: new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59)
            }).data("kendoTimePicker");

            //NumericTextbox
            MaxCountApply = $("#MaxCountApply").kendoNumericTextBox({
                format: "n",
                decimals: 2,
                value: 0
            }).data("kendoNumericTextBox");
            FromAmount = $("#FromAmount").kendoNumericTextBox({
                format: "n",
                decimals: 2,
                value: 0
            }).data("kendoNumericTextBox");
            ToAmount = $("#ToAmount").kendoNumericTextBox({
                format: "n",
                decimals: 3,
                value: 0
            }).data("kendoNumericTextBox");
            BudgetAmount = $("#BudgetAmount").kendoNumericTextBox({
                format: "n",
                decimals: 2,
                value: 0
            }).data("kendoNumericTextBox");
            FromQuantity = $("#FromQuantity").kendoNumericTextBox({
                format: "n",
                decimals: 2,
                value: 0
            }).data("kendoNumericTextBox"); ;
            ToQuantity = $("#ToQuantity").kendoNumericTextBox({
                format: "n",
                decimals: 2,
                value: 0
            }).data("kendoNumericTextBox");
            TargetRevenue = $("#TargetRevenue").kendoNumericTextBox({
                format: "n",
                decimals: 2,
                value: 0
            }).data("kendoNumericTextBox");
            DiscountValue = $("#DiscountValue").kendoNumericTextBox({
                format: "n",
                decimals: 2,
                value: 0
            }).data("kendoNumericTextBox");
            //Combobox
            var viewModel = kendo.observable({
                allowCustomValues: false,
                customerData: new kendo.data.DataSource({
                    transport: {
                        read: {
                            type: "GET",
                            url: "PromotionDetail.aspx/GetAllReferenceValueByType",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        parameterMap: function (data, operation) {
                            return { valueType: "DiscountType" };
                        },
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return data;
                            }
                        },
                        allowCustomValues: false,
                        model: {
                            id: "ReferenceValue",
                            fields: {
                                ReferenceValue: { type: "string", validation: { required: true} },
                                ReferenceName: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                })
            });
            dllDiscount = $("#DiscountType").kendoDropDownList({
                autoBind: false,
                filter: "contains",
                optionLabel: "[Select Discount Type]",
                dataTextField: "ReferenceName",
                dataValueField: "ReferenceValue",
                suggest: true,
                required: true,
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "PromotionDetail.aspx/GetAllReferenceValueDiscount",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        }
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return data;
                            }
                        },
                        allowCustomValues: false,
                        model: {
                            id: "ReferenceValue",
                            fields: {
                                ReferenceValue: { type: "string", validation: { required: true} },
                                ReferenceName: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                }
            });
            ddlPromotion = $("#PromotionType").kendoDropDownList({
                autoBind: false,
                filter: "contains",
                optionLabel: "[Select Promotion Type]",
                dataTextField: "ReferenceName",
                dataValueField: "ReferenceValue",
                suggest: true,
                required: true,
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "PromotionDetail.aspx/GetAllReferenceValuePromotion",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        }
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return data;
                            }
                        },
                        allowCustomValues: false,
                        model: {
                            id: "ReferenceValue",
                            fields: {
                                ReferenceValue: { type: "string", validation: { required: true} },
                                ReferenceName: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                }
            });
            IsInsert = '<%= Request.QueryString["IsInsert"] %>';
            promotionID = '<%= Request.QueryString["PromotionID"] %>';
            if (promotionID.length > 0) {
                GetDocPromotionHeader();
            }
        });
    </script>
    <table style="width: 100%;">
        <tr>
            <td align="center">
                <table style="border-collapse: collapse;" border="0">
                    <tr>
                        <td style="width: 170px;">
                            <label for="PromotionID">
                                PromotionID</label>
                        </td>
                        <td style="width: 230px;">
                            <input type="text" class="k-input k-textbox" name="PromotionID" id="PromotionID"
                                readonly="readonly" />
                        </td>
                        <td style="width: 120px;">
                            <label for="PromotionCode">
                                Prom. Code</label>
                        </td>
                        <td style="width: 230px;">
                            <input type="text" class="k-input k-textbox" name="PromotionCode" id="PromotionCode"
                                required="required" validationmessage="Pls input Promotion Code." />
                        </td>
                        <td style="width: 200px;">
                            <label for="PromotionName">
                                Prom. Name</label>
                        </td>
                        <td style="width: 230px;">
                            <input type="text" class="k-input k-textbox" name="PromotionName" id="PromotionName"
                                required="required" validationmessage="Pls input Promotion Name." />
                            <span class="fake">&nbsp;</span></td>
                        <td style="width: 110px;">
                            &nbsp;<label for="IsActive">Active</label>
                        </td>
                        <td style="width: 100px;">
                            <input type="checkbox" name="IsActive" id="IsActive" />
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 100px;">
                            <label for="FatherPromotionCode">
                                Father Prom. Code</label>
                        </td>
                        <td>
                            <input type="text" class="k-input k-textbox" name="FatherPromotionCode" id="FatherPromotionCode"
                                 />
                        </td>
                        <td>
                            <label for="PromotionType">
                                Prom. Type</label>
                        </td>
                        <td>
                            <input type="text" name="PromotionType" required="required" validationmessage="Pls select Promotion Type."
                                id="PromotionType" />
                            <span class="k-invalid-msg" data-for="PromotionType"></span><span class="fake">&nbsp;</span></td>
                        <td style="width: 100px;">
                            <label for="BudgetAmount">
                                Budget Amt.</label>
                        </td>
                        <td>
                            <input type="text" id="BudgetAmount" name="BudgetAmount" />
                        </td>
                        <td>
                            &nbsp;<label for="IsOpional">Opional</label>
                        </td>
                        <td>
                            <input type="checkbox" name="IsOpional" id="IsOpional" />
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 100px;">
                            <label for="FromDate">
                                From Date</label>
                        </td>
                        <td>
                            <input type="text" name="FromDate" style="width: 199px;" id="FromDate" />
                        </td>
                        <td>
                            <label for="ToDate">
                                To Date</label>
                        </td>
                        <td>
                            <input type="text" name="ToDate" style="width: 199px;" id="ToDate" />
                        </td>
                        <td style="width: 100px;">
                            <label for="TargetRevenue">
                                Target Revenue</label>
                        </td>
                        <td>
                            <input type="text" id="TargetRevenue" name="TargetRevenue" />
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 100px;">
                            <label for="FromTime">
                                From Time</label>
                        </td>
                        <td>
                            <input type="text" name="FromTime" id="FromTime" />
                        </td>
                        <td>
                            <label for="ToTime">
                                To Time</label>
                        </td>
                        <td>
                            <input type="text" name="ToTime" id="ToTime" />
                        </td>
                        <td style="width: 100px;">
                            <label for="MaxCountApply">
                                Max Count Apply</label>
                        </td>
                        <td>
                            <input type="text" id="MaxCountApply" name="MaxCountApply" />
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 100px;">
                            <label for="FromAmount">
                                From Amount</label>
                        </td>
                        <td>
                            <input type="text" id="FromAmount" name="FromAmount" />
                        </td>
                        <td>
                            <label for="ToAmount">
                                To Amount</label>
                        </td>
                        <td>
                            <input type="text" id="ToAmount" name="ToAmount" />
                        </td>
                        <td style="width: 100px;">
                            <label for="DiscountType">
                                Disc. Type</label>
                        </td>
                        <td>
                            <input type="text" id="DiscountType" name="DiscountType" required="required" validationmessage="Pls select Discount Type." /></td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 100px;">
                            <label for="FromQuantity">
                                From Quantity</label>
                        </td>
                        <td>
                            <input type="text" id="FromQuantity" name="FromQuantity" />
                        </td>
                        <td>
                            <label for="ToQuantity">
                                To Quantity</label>
                        </td>
                        <td>
                            <input type="text" id="ToQuantity" name="ToQuantity" />
                        </td>
                        <td style="width: 100px;">
                            <label for="DiscountValue">
                                Disc. Value</label>
                        </td>
                        <td>
                            <input type="text" id="DiscountValue" name="DiscountValue" />
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <hr />
    <table style="width: 100%;">
        <tr>
            <td align="center">
                <table border="0" style="border-collapse: collapse;">
                    <tr>
                        <td>
                            <label for="Monday">
                                Monday</label>
                        </td>
                        <td>
                            <label for="Tuesday">
                                Tuesday</label>
                        </td>
                        <td>
                            <label for="Wednesday">
                                Wednesday</label>
                        </td>
                        <td>
                            <label for="Thursday">
                                Thursday</label>
                        </td>
                        <td>
                            <label for="Friday">
                                Friday</label>
                        </td>
                        <td>
                            <label for="Saturday">
                                Saturday</label>
                        </td>
                        <td>
                            <label for="Sunday">
                                Sunday</label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="checkbox" name="Monday" id="Monday" />
                        </td>
                        <td>
                            <input type="checkbox" name="Tuesday" id="Tuesday">
                        </td>
                        <td>
                            <input type="checkbox" name="Wednesday" id="Wednesday" />
                        </td>
                        <td>
                            <input type="checkbox" name="Thursday" id="Thursday" />
                        </td>
                        <td>
                            <input type="checkbox" name="Friday" id="Friday">
                        </td>
                        <td>
                            <input type="checkbox" name="Saturday" id="Saturday">
                        </td>
                        <td>
                            <input type="checkbox" name="Sunday" id="Sunday">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="MondayStart">
                                Monday Start</label>
                        </td>
                        <td>
                            <label for="TuesdayStart">
                                Tuesday Start</label>
                        </td>
                        <td>
                            <label for="WednesdayStart">
                                Wednesday Start</label>
                        </td>
                        <td>
                            <label for="ThursdayStart">
                                Thursday Start</label>
                        </td>
                        <td>
                            <label for="FridayStart">
                                Friday Start
                            </label>
                        </td>
                        <td>
                            <label for="SaturdayStart">
                                Saturday Start</label>
                        </td>
                        <td>
                            <label for="SundayStart">
                                Sunday Start</label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="text" name="MondayStart" id="MondayStart" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="TuesdayStart" id="TuesdayStart" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="WednesdayStart" id="WednesdayStart" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="ThursdayStart" id="ThursdayStart" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="FridayStart" id="FridayStart" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="SaturdayStart" id="SaturdayStart" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="SundayStart" id="SundayStart" style="width: 120px;" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="MondayEnd">
                                Monday End</label>
                        </td>
                        <td>
                            <label for="TuesdayEnd">
                                Tuesday End</label>
                        </td>
                        <td>
                            <label for="WednesdayEnd">
                                Wednesday End</label>
                        </td>
                        <td>
                            <label for="ThursdayEnd">
                                Thursday End</label>
                        </td>
                        <td>
                            <label for="FridayEnd">
                                Friday End
                            </label>
                        </td>
                        <td>
                            <label for="SaturdayEnd">
                                Saturday End</label>
                        </td>
                        <td>
                            <label for="SundayEnd">
                                Sunday End</label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="text" name="MondayEnd" id="MondayEnd" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="TuesdayEnd" id="TuesdayEnd" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="WednesdayEnd" id="WednesdayEnd" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="ThursdayEnd" id="ThursdayEnd" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="FridayEnd" id="FridayEnd" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="SaturdayEnd" id="SaturdayEnd" style="width: 120px;" />
                        </td>
                        <td>
                            <input type="text" name="SundayEnd" id="SundayEnd" style="width: 120px;" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</asp:Content>
